/**
 * 
 */
package swt.action;

import java.util.Date;
import java.util.Timer;
import java.util.logging.Logger;

import swt.commons.Const;
import swt.commons.LogUtil;
import swt.commons.Utils;

/**
 * @author Thuc
 *
 */
public class CountdownAction {

	private static Logger log = LogUtil.getLogger();
	
	private String hour;
	
	private String minute;
	
	private String day;
	
	private Timer timer;
	
	/**
	 * Constructor
	 * @param hour
	 * @param minute
	 */
	public CountdownAction(String day, String hour, String minute) {
		this.day = day;
		this.hour = hour;
		this.minute = minute;
	}

	/**
	 * main process
	 */
	public void run() {
		log.info("Shutdown time = " + this.day + " " + this.hour + ":" + this.minute + ":00");
		String date = this.day + this.hour + ":" + this.minute + ":00";
		Date shutdownPointTime = Utils.toDate(date, Const.DATE_FORMAT + Const.TIME_FORMAT_24);
		long miliseconds = shutdownPointTime.getTime();
		
		Task task = new Task(miliseconds);
		timer = new Timer();
		timer.schedule(task,0L, 1000L);
	}

	public void dispose(){
		timer.cancel();
	}
}
